{extend name="public/base"}

{block name="title"}就行天下-个人中心{/block}

{block name="style"}
<link rel="stylesheet" href="__STATIC__/home/css/set.css" />
{js href="__STATIC__/home/css/jquery.jcrop.min.css" /}
<style>
    .weui-picker-modal .picker-item {
        padding: 0 25px;
    }
</style>
{/block}


{block name="main"}
<div class="pageControl bg-f5 personalMessage">
    <div class="main-top"></div>
    <div class="msui_nav msui_navTop">
        <a class="msui_navTop-back" href="javascript:history.back();"><i class="micon-back"></i></a>
        <h1 class="msui_navTop-title">个人信息</h1>
        <a href="" class="msui_navTop-right msui_navTop-cnav"><i class="micon-cnav"></i></a>
    </div>
    <div class="weui-cell bg-f5">
        <div class="weui-cell__bd">
            <span class="fs065 ">个人资料</span>
        </div>
    </div>
    <div class="weui-cell weui-cell_access">
        <div class="weui-cell__hd">
            <img class="headimgurl" src="{$data.headimgurl|default='__STATIC__/home/images/2.jpg'}">
        </div>
        <div class="weui-cell__bd">
            <p class="fs065 cl-9999">修改头像</p>
            <input class="uploaderInput weui-uploader__input" type="file" accept="image/*" data-field="headimgurl" data-quantity="pic" data-width="100" data-height="100"/>
            <input type="hidden" name="headimgurl" value="{$data.headimgurl|default=''}">
        </div>
        <div class="weui-cell__ft"></div>
    </div>
    <a  class="weui-cell weui-cell_access open-popup" href="javascript:;" data-target="#userName">
        <div class="weui-cell__hd">
            <p class="fs065 cl-9999">昵称</p>
        </div>
        <div class="weui-cell__bd">
            <input type="text" placeholder="" class="weui-input userName" value="{$data.nickname|default=''}">
        </div>
        <div class="weui-cell__ft"></div>
    </a>
    <a class="weui-cell weui-cell_access " href="javascript:;">
        <div class="weui-cell__hd">
            <p class="fs065 cl-9999">性别</p>
        </div>
        <div class="weui-cell__bd">
            <input type="text" placeholder="" class="weui-input" value="{$data.sex|default='男'}" id="sex">
        </div>
        <div class="weui-cell__ft"></div>
    </a>
    <a class="weui-cell weui-cell_access" href="javascript:;">
        <div class="weui-cell__hd">
            <p class="fs065 cl-9999">生日</p>
        </div>
        <div class="weui-cell__bd">
            <input class="weui-input no_h_i_s" placeholder="请输入出生日期" id="date3" type="text" value="{gt name='data.birthday' value='0'}{$data.birthday|date='Y年m月d日', ###}{/gt}" readonly="">
        </div>
        <div class="weui-cell__ft"></div>
    </a>
</div>
<!--修改头像-->
<div id="headPortrait"  class="weui-popup__container popup-bottom">
    <div class="weui-popup__overlay"></div>
    <div class="weui-popup__modal">
        <div class="modal-content">
            <div class="customService_a">
                <a href="" class="cl-219">打开照相机</a>
                <a href="" class="cl-219">从手机相机获取</a>
            </div>
            <a href="javascript:;" class="picker-btn2 close-popup cl-219">取消</a>
        </div>
    </div>
</div>
<!--修改昵称-->
<div id="userName"  class="weui-popup__container bg-fff">
    <div class="weui-popup__overlay bg-f5"></div>
    <div class="weui-popup__modal">
        <div class="modal-content">
            <div class="msui_nav msui_navTop">
                <a class="msui_navTop-back close-popup" href="javascript:;"><i class="micon-back"></i></a>
                <h1 class="msui_navTop-title">修改昵称</h1>
                <a href="" class="msui_navTop-right userNameOk cl-c40">完成</i></a>
            </div>
            <div class="weui-cell bg-f5">
                <div class="weui-cell__bd">
                    <span class="fs06">由中英文好人数字组成</span>
                </div>
            </div>
            <div class="weui-cell">
                <div class="weui-cell__bd">
                    <input type="text" placeholder="" class="weui-input amendUserName" value="{$data.nickname|default=''}">
                </div>
            </div>
        </div>
    </div>
</div>
{/block}

{block name="javascript"}
{js href="__STATIC__/home/js/jquery.jcrop.min.js" /}
{js href="__STATIC__/home/js/jquery.jcrop.upload.js" /}
{js href="__STATIC__/home/js/exif.js" /}
<script>
    SCOPE.upload_img_type = 1;
    SCOPE.save_member_info_field = '';
    $(function() {

        $("#sex").picker({
            toolbarCloseText:'确认',
            title: "请选择性别",
            cols: [
                {
                    textAlign: 'center',
                    values: ['男', '女', '保密']
                }
            ],
            onChange : function (values) {
                SCOPE.save_member_info_field = 'sex';
                SCOPE.save_member_info_value = values.value[0];
                //save_member_info('sex', values.value);
            }
        });
//        修改昵称
        $('.userNameOk').click(function (e) {
            e.preventDefault();
            var tt = $('.amendUserName').val();
            console.log(tt);
            $.closePopup();
            $('.userName').val(tt);
            save_member_info('nickname', tt);
        });
        $("#date2").calendar({
            dateFormat: 'yyyy年mm月dd日'
        });
        $("#date3").datetimePicker({
            toolbarCloseText:'确认',
            title: '生日',
            yearSplit: '年',
            monthSplit: '月',
            dateSplit: '日',
            times: function () {
                return [];
            },
            onChange: function (picker, values, displayValues) {
//                console.log()
                SCOPE.save_member_info_field = 'birthday';
                SCOPE.save_member_info_value = values[0] + '-' + values[1] + '-' + values[2];
            }
        });
        $(document).on("click", ".weui-picker-modal .toolbar .picker-button", function () {
            save_member_info(SCOPE.save_member_info_field, SCOPE.save_member_info_value);
        });
    });

    function save_member_info(_field, _value) {
        $.showLoading();
        $.ajax({
            type : 'POST',
            url : '{:url("save_member_role_info")}',
            data : {
                field : _field,
                value : _value
            },
            dataType : 'json',
            success : function (msg) {
                if (msg.code == 200) {
                    $.toptip('修改成功！', 'success');
                } else {
                    $.toptip(msg.msg);
                }
                console.log(msg);
                $.hideLoading();
            }
        });
    }
</script>
{/block}